package cn.itcast.oa.util;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.WebApplicationContextUtils;

import cn.itcast.oa.domain.Privilege;
import cn.itcast.oa.service.PrivilegeService;

@Component
public class initListener implements ServletContextListener {
//
//	@Resource
//	private PrivilegeService privilegeService ;
	
	public void contextInitialized(ServletContextEvent sce) {
		//获取容器与相关的Service对象
		
		ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()) ;
		PrivilegeService privilegeService = (PrivilegeService) ac.getBean("PrivilegeServiceImpl");
		
		List<Privilege> topPrivilegeList = privilegeService.findTopList() ;
		sce.getServletContext().setAttribute("topPrivilegeList", topPrivilegeList);
		System.out.println("-------->已准备数据<---------");
	}
	

	public void contextDestroyed(ServletContextEvent arg0) {

	}

}
